package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.domain.vo.NetworkClientGoRankVo;
import com.ruoyi.logistic.domain.vo.NetworkClientGoVo;
import com.ruoyi.logistic.mapper.NetworkClientTagMapper;
import com.ruoyi.logistic.service.NetworkClientGoService;
import com.ruoyi.logistic.service.NetworkClientTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/clientGo")
@RestController
@Api(tags = "网点财务_客户流向结构分析")
public class NetworkClientGoController {
    @Autowired
    private NetworkClientGoService networkClientGoService;
    @Autowired
    private NetworkClientTagService networkClientTagService;

    @ApiOperation("显示客户流向明细列表")
    @GetMapping("/selectDetailAll")
    public R selectAll(PageDate pageDate){
        List<NetworkClientGoDetail> clientGoDetailList = networkClientGoService.selectAll(pageDate);
        if (clientGoDetailList == null || clientGoDetailList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(clientGoDetailList));
        }
    }
//    @ApiOperation("添加客户流向明细")
//    @PostMapping("/insertDetail")
//    public R insert(@RequestBody NetworkClientGoDetail networkClientGoDetail){
//        Boolean isAdd = networkClientGoService.insert(networkClientGoDetail);
//        if (isAdd){
//            return R.ok("添加成功");
//        }else {
//            return R.fail("添加失败");
//        }
//    }
//    @ApiOperation("修改客户流向明细")
//    @PostMapping("/updateDetail")
//    public R update(@RequestBody NetworkClientGoDetail networkClientGoDetail){
//        Boolean isUpdate = networkClientGoService.update(networkClientGoDetail);
//        if (isUpdate){
//            return R.ok("修改成功");
//        }else {
//            return R.fail("修改失败");
//        }
//    }
//    @ApiOperation("删除客户流向明细")
//    @PostMapping("/deleteDetailById")
//    public R deleteById(Integer id){
//        Boolean isDelete = networkClientGoService.deleteById(id);
//        if (isDelete){
//            return R.ok("删除成功");
//        }else {
//            return R.fail("删除失败");
//        }
//    }
    @ApiOperation("搜索客户流向明细")
    @PostMapping("/searchDetail")
    public R searchDetail(@RequestBody NetworkClientGoVo vo){
        List<NetworkClientGoDetail> clientGoDetailList = networkClientGoService.search(vo);
        if (clientGoDetailList == null || clientGoDetailList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(clientGoDetailList));
        }
    }

    @ApiOperation("汇总客户流向明细")
    @PostMapping("/clientGoCollect")
    public R clientGoCollect(@RequestBody NetworkClientGoVo vo){
        List<NetworkClientGoCollect> clientGoCollects = networkClientGoService.clientGoCollect(vo);
        if (clientGoCollects == null || clientGoCollects.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(clientGoCollects));
        }
    }

    @ApiOperation("目的省份收入总和排名")
    @PostMapping("/provinceIncomeRank")
    public R provinceIncomeRank(@RequestBody NetworkClientGoRankVo vo){
        List<NetworkClientGoProvinceIncomeRank> incomeRanks = networkClientGoService.provinceIncomeRank(vo);
        if (incomeRanks == null || incomeRanks.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(incomeRanks);
        }
    }

    @ApiOperation("客户收入总和排名")
    @PostMapping("/clientIncomeRank")
    public R clientIncomeRank(@RequestBody NetworkClientGoRankVo vo){
        NetworkClientGoClientIncomeRankAll clientIncomeRanks = networkClientGoService.clientIncomeRank(vo);
        if (clientIncomeRanks == null){
            return R.fail("暂无数据");
        }else {
            return R.ok(clientIncomeRanks);
        }
    }

    @ApiOperation("客户名称模糊查询")
    @GetMapping("selectByName")
    public R selectByName(String name){
        return R.ok(networkClientTagService.selectByName(name));
    }
}
